import { createElement } from 'react';
import dynamic from 'dva/dynamic';
import { getMenuData } from './menu';
import { hasAuthority, hasRole, hasProduct } from '../utils/authority';


let routerDataCache;

const modelNotExisted = (app, model) => (
  // eslint-disable-next-line
  !app._models.some(({ namespace }) => {
    return namespace === model.substring(model.lastIndexOf('/') + 1);
  })
);

// wrapper of dynamic
const dynamicWrapper = (app, models, component) => {
  // () => require('module')
  // transformed by babel-plugin-dynamic-import-node-sync
  if (component.toString().indexOf('.then(') < 0) {
    models.forEach((model) => {
      if (modelNotExisted(app, model)) {
        // eslint-disable-next-line
        app.model(require(`../models/${model}`).default);
      }
    });
    return (props) => {
      if (!routerDataCache) {
        routerDataCache = getRouterData(app);
      }
      return createElement(component().default, {
        ...props,
        routerData: routerDataCache,
      });
    };
  }
  // () => import('module')
  return dynamic({
    app,
    models: () => models.filter(
      model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`)
      ),
    // add routerData prop
    component: () => {
      if (!routerDataCache) {
        routerDataCache = getRouterData(app);
      }
      return component().then((raw) => {
        const Component = raw.default || raw;
        return props => createElement(Component, {
          ...props,
          routerData: routerDataCache,
        });
      });
    },
  });
};

function getFlatMenuData(menus) {
  let keys = {};
  menus.forEach((item) => {
    if (item.children) {
      keys[item.path] = { ...item };
      keys = { ...keys, ...getFlatMenuData(item.children) };
    } else {
      keys[item.path] = { ...item };
    }
  });
  return keys;
}

export const getRouterData = (app) => {
  const routerConfig = {
    '/': {
      component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
    },

    '/userCenter': {
      component: dynamicWrapper(app, ['user', 'SystemManagement/systemUser'], () => import('../routes/HomePage/UserCenter')),
    },

    '/homePage': {
      component: dynamicWrapper(app, ['HomePage/homePage'], () => import('../routes/HomePage/HomePage')),
    },


    '/productManagement/product': {
      component: dynamicWrapper(app, ['ProductManagement/product'], () => import('../routes/ProductManagement/Product')),
    },
    '/productManagement/productCategory': {
      component: dynamicWrapper(app, ['ProductManagement/productCategory'], () => import('../routes/ProductManagement/ProductCategory')),
    },
    '/productManagement/productJD': {
      component: dynamicWrapper(app, ['ProductManagement/product'], () => import('../routes/ProductManagement/Product')),
    },

    '/userManagement/conversionDetail': {
      component: dynamicWrapper(app, ['UserManagement/conversionDetail'], () => import('../routes/UserManagement/ConversionDetail')),
    },
    '/userManagement/conversionGeneral': {
      component: dynamicWrapper(app, ['UserManagement/conversionGeneral'], () => import('../routes/UserManagement/ConversionGeneral')),
    },
    '/userManagement/creditCheck': {
      component: dynamicWrapper(app, ['UserManagement/creditCheck'], () => import('../routes/UserManagement/CreditCheck')),
    },
    '/userManagement/userList': {
      component: dynamicWrapper(app, ['UserManagement/userList'], () => import('../routes/UserManagement/UserList')),
    },

    '/orderManagement/businessOrder': {
      component: dynamicWrapper(app, ['OrderManagement/businessOrder'], () => import('../routes/OrderManagement/BusinessOrder')),
    },
    '/orderManagement/refundOrder': {
      component: dynamicWrapper(app, ['OrderManagement/refundOrder'], () => import('../routes/OrderManagement/RefundOrder')),
    },
    '/orderManagement/refundOrderDetail': {
      component: dynamicWrapper(app, ['OrderManagement/refundOrderDetail'], () => import('../routes/OrderManagement/RefundOrderDetail')),
    },
    '/orderManagement/instalmentWaitPayOrder': {
      component: dynamicWrapper(app, ['OrderManagement/instalmentWaitPayOrder'], () => import('../routes/OrderManagement/InstalmentWaitPayOrder')),
    },
    '/orderManagement/instalmentAlreadyPayOrder': {
      component: dynamicWrapper(app, ['OrderManagement/instalmentAlreadyPayOrder'], () => import('../routes/OrderManagement/InstalmentAlreadyPayOrder')),
    },

    //sdfz
    '/assetsManagement/totalList': {
      component: dynamicWrapper(app, ['OrderManagement/totalList'], () => import ('../routes/OrderManagement/TotalList')),
    },
    '/assetsManagement/withdrawCreated': {
      component: dynamicWrapper(app, ['OrderManagement/withdrawBill'], () => import('../routes/OrderManagement/WithdrawCreated')),
    },
    '/assetsManagement/withdrawTransferring': {
      component: dynamicWrapper(app, ['OrderManagement/withdrawBill'], () => import('../routes/OrderManagement/WithdrawTransferring')),
    },
    '/assetsManagement/withdrawTransferFail': {
      component: dynamicWrapper(app, ['OrderManagement/withdrawBill'], () => import('../routes/OrderManagement/WithdrawTransferFail')),
    },
    '/assetsManagement/withdrawWaitToRepay': {
      component: dynamicWrapper(app, ['OrderManagement/withdrawBill'], () => import('../routes/OrderManagement/WithdrawWaitToRepay')),
    },
    '/assetsManagement/withdrawHaveRepayed': {
      component: dynamicWrapper(app, ['OrderManagement/withdrawBill'], () => import('../routes/OrderManagement/WithdrawHaveRepayed')),
    },

    //想美
    '/xbeautyManagement/totalList': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanList'], () => import ('../routes/XBeautyManagement/TotalList')),
    },
    '/xbeautyManagement/loanCreated': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import('../routes/XBeautyManagement/LoanCreated')),
    },
    '/xbeautyManagement/loanTransferring': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import('../routes/XBeautyManagement/LoanTransferring')),
    },
    '/xbeautyManagement/loanTransferFail': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import('../routes/XBeautyManagement/LoanTransferFail')),
    },
    '/xbeautyManagement/loanWaitToRepay': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import('../routes/XBeautyManagement/LoanWaitToRepay')),
    },
    '/xbeautyManagement/loanHaveRepayed': {
      component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import('../routes/XBeautyManagement/LoanHaveRepayed')),
    },

    '/operatingCenter/redPacketConfig': {
      component: dynamicWrapper(app, ['OperatingCenter/redPacketConfig'], () => import('../routes/OperatingCenter/RedPacketConfig')),
    },
    '/operatingCenter/redPacketStatistics': {
      component: dynamicWrapper(app, ['OperatingCenter/redPacketStatistics'], () => import('../routes/OperatingCenter/RedPacketStatistics')),
    },
    '/operatingCenter/bannerConfig': {
      component: dynamicWrapper(app, ['OperatingCenter/bannerConfig'], () => import('../routes/OperatingCenter/BannerConfig')),
    },
    '/operatingCenter/flickerScreen': {
      component: dynamicWrapper(app, ['OperatingCenter/flickerScreen'], () => import('../routes/OperatingCenter/FlickerScreen')),
    },
    '/operatingCenter/homepageIcon': {
      component: dynamicWrapper(app, ['OperatingCenter/homepageIcon'], () => import('../routes/OperatingCenter/HomepageIcon')),
    },
    '/operatingCenter/classifyIcon': {
      component: dynamicWrapper(app, ['OperatingCenter/classifyIcon'], () => import('../routes/OperatingCenter/ClassifyIcon')),
    },
    '/operatingCenter/loanSupermarket': {
      component: dynamicWrapper(app, ['OperatingCenter/loanSupermarket'], () => import('../routes/OperatingCenter/LoanSupermarket')),
    },
    '/operatingCenter/stageConfig': {
      component: dynamicWrapper(app, ['OperatingCenter/stageConfig'], () => import('../routes/OperatingCenter/StageConfig')),
    },
    '/operatingCenter/functionSlot': {
      component: dynamicWrapper(app, ['OperatingCenter/functionSlot'], () => import('../routes/OperatingCenter/FunctionSlot')),
    },



    '/operatingCenterForXbeauty/bannerConfig': {
      component: dynamicWrapper(app, ['OperatingCenter/bannerConfig'], () => import('../routes/OperatingCenter/BannerConfig')),
    },
    '/operatingCenterForXbeauty/flickerScreen': {
      component: dynamicWrapper(app, ['OperatingCenter/flickerScreen'], () => import('../routes/OperatingCenter/FlickerScreen')),
    },
    '/operatingCenterForXbeauty/homepageIcon': {
      component: dynamicWrapper(app, ['OperatingCenter/homepageIcon'], () => import('../routes/OperatingCenter/HomepageIcon')),
    },
    '/operatingCenterForXbeauty/loanSupermarket': {
      component: dynamicWrapper(app, ['OperatingCenter/loanSupermarket'], () => import('../routes/OperatingCenter/LoanSupermarket')),
    },
  '/operatingCenterForXbeauty/stageConfig': {
    component: dynamicWrapper(app, ['OperatingCenter/stageConfig'], () => import('../routes/OperatingCenter/StageConfig')),
  },
  '/operatingCenterForXbeauty/functionSlot': {
    component: dynamicWrapper(app, ['OperatingCenter/functionSlot'], () => import('../routes/OperatingCenter/FunctionSlot')),
  },

  '/customerManagement/customer': {
      component: dynamicWrapper(app, ['CustomerManagement/customer'], () => import('../routes/CustomerManagement/Customer')),
    },

    '/systemManagement/systemUser': {
      component: dynamicWrapper(app, ['SystemManagement/systemUser'], () => import('../routes/SystemManagement/SystemUser')),
    },
    '/systemManagement/systemOrganization': {
      component: dynamicWrapper(app, ['SystemManagement/systemOrganization'], () => import('../routes/SystemManagement/SystemOrganization')),
    },
    '/systemManagement/systemRole': {
      component: dynamicWrapper(app, ['SystemManagement/systemRole'], () => import('../routes/SystemManagement/SystemRole')),
    },
    '/systemManagement/systemAuth': {
      component: dynamicWrapper(app, ['SystemManagement/systemAuth'], () => import('../routes/SystemManagement/SystemAuth')),
    },

  '/statisticsCenter/conversionData': {
    component: dynamicWrapper(app, ['StatisticsCenter/conversionData'], () => import('../routes/StatisticsCenter/ConversionData')),
  },
  '/statisticsCenter/backStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenter/backStatistics'], () => import('../routes/StatisticsCenter/BackStatistics')),
  },
  '/statisticsCenter/loanStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenter/loanStatistics'], () => import('../routes/StatisticsCenter/LoanStatistics')),
  },
  '/statisticsCenter/grossProfit': {
    component: dynamicWrapper(app, ['StatisticsCenter/grossProfit'], () => import('../routes/StatisticsCenter/GrossProfit')),
  },
  '/statisticsCenter/riskManagement': {
    component: dynamicWrapper(app, ['StatisticsCenter/riskManagement'], () => import('../routes/StatisticsCenter/RiskManagement')),
  },
  '/statisticsCenter/overdueStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenter/overdueStatistics'], () => import('../routes/StatisticsCenter/OverdueStatistics')),
  },
  '/statisticsCenterForXBeauty/conversionData': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/conversionData'], () => import('../routes/StatisticsCenterForXBeauty/ConversionData')),
  },
  '/statisticsCenterForXBeauty/backStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/backStatistics'], () => import('../routes/StatisticsCenterForXBeauty/BackStatistics')),
  },
  '/statisticsCenterForXBeauty/grossProfit': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/grossProfit'], () => import('../routes/StatisticsCenterForXBeauty/GrossProfit')),
  },
  '/statisticsCenterForXBeauty/riskManagement': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/riskManagement'], () => import('../routes/StatisticsCenterForXBeauty/RiskManagement')),
  },
  '/statisticsCenterForXBeauty/loanStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/loanStatistics'], () => import('../routes/StatisticsCenterForXBeauty/LoanStatistics')),
  },
  '/statisticsCenterForXBeauty/overdueStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/overdueStatistics'], () => import('../routes/StatisticsCenterForXBeauty/OverdueStatistics')),
  },

  '/channelCenter/channelStatistics': {
    component: dynamicWrapper(app, ['ChannelCenter/channelStatistics'], () => import('../routes/ChannelCenter/ChannelStatistics')),
  },
  '/channelCenter/channelDetail': {
    component: dynamicWrapper(app, ['ChannelCenter/channelStatistics'], () => import('../routes/ChannelCenter/ChannelDetails')),
  },
  '/channelCenter/channelConversion': {
    component: dynamicWrapper(app, ['ChannelCenter/channelConversion'], () => import('../routes/ChannelCenter/ChannelConversion')),
  },

  '/channelCenterForXBeauty/channelStatistics': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import('../routes/ChannelCenterForXBeauty/ChannelStatistics')),
  },
  '/channelCenterForXBeauty/channelDetail': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import('../routes/ChannelCenterForXBeauty/ChannelDetails')),
  },
  '/channelCenterForXBeauty/channelConversion': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelConversion'], () => import('../routes/ChannelCenterForXBeauty/ChannelConversion')),
  },

  '/financeCenter/expenseDetail': {
    component: dynamicWrapper(app, ['FinanceCenter/expenseDetail'], () => import('../routes/FinanceCenter/ExpenseDetail')),
  },

  '/riskCenter/riskDetection': {
    component: dynamicWrapper(app, ['RiskCenter/riskDetection'], () => import('../routes/RiskCenter/RiskDetection')),
  },

  //信花花路由部分

  '/assetsManagementForXflower/totalList': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanList'], () => import ('../routes/XBeautyManagement/TotalList')),
  },
  '/assetsManagementForXflower/loanCreated': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/OrderManagementForXflower/LoanCreated')),
  },
  '/assetsManagementForXflower/loanTransferring': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanTransferring')),
  },
  '/assetsManagementForXflower/loanTransferFail': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanTransferFail')),
  },
  '/assetsManagementForXflower/loanWaitToRepay': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanWaitToRepay')),
  },
  '/assetsManagementForXflower/loanHaveRepayed': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanHaveRepayed')),
  },

  '/operatingCenterForXflower/bannerConfig': {
    component: dynamicWrapper(app, ['OperatingCenter/bannerConfig'], () => import ('../routes/OperatingCenter/BannerConfig')),
  },
  '/operatingCenterForXflower/flickerScreen': {
    component: dynamicWrapper(app, ['OperatingCenter/flickerScreen'], () => import ('../routes/OperatingCenter/FlickerScreen')),
  },
  '/operatingCenterForXflower/homepageIcon': {
    component: dynamicWrapper(app, ['OperatingCenter/homepageIcon'], () => import ('../routes/OperatingCenter/HomepageIcon')),
  },
  '/operatingCenterForXflower/loanSupermarket': {
    component: dynamicWrapper(app, ['OperatingCenter/loanSupermarket'], () => import ('../routes/OperatingCenter/LoanSupermarket')),
  },
  '/operatingCenterForXflower/stageConfig': {
    component: dynamicWrapper(app, ['OperatingCenter/stageConfig'], () => import('../routes/OperatingCenter/StageConfig')),
  },
  '/operatingCenterForXflower/functionSlot': {
    component: dynamicWrapper(app, ['OperatingCenter/functionSlot'], () => import('../routes/OperatingCenter/FunctionSlot')),
  },

  '/statisticsCenterForXflower/conversionData': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/conversionData'], () => import ('../routes/StatisticsCenterForXBeauty/ConversionData')),
  },
  '/statisticsCenterForXflower/backStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/backStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/BackStatistics')),
  },
  '/statisticsCenterForXflower/grossProfit': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/grossProfit'], () => import ('../routes/StatisticsCenterForXBeauty/GrossProfit')),
  },
  '/statisticsCenterForXflower/riskManagement': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/riskManagement'], () => import ('../routes/StatisticsCenterForXBeauty/RiskManagement')),
  },
  '/statisticsCenterForXflower/loanStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/loanStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/LoanStatistics')),
  },
  '/statisticsCenterForXflower/overdueStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/overdueStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/OverdueStatistics')),
  },

  '/channelCenterForXflower/channelStatistics': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import ('../routes/ChannelCenterForXBeauty/ChannelStatistics')),
  },
  '/channelCenterForXflower/channelDetail': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import ('../routes/ChannelCenterForXBeauty/ChannelDetails')),
  },
  '/channelCenterForXflower/channelConversion': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelConversion'], () => import ('../routes/ChannelCenterForXBeauty/ChannelConversion')),
  },

  //有点路由部分

  '/assetsManagementForUpoint/totalList': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanList'], () => import ('../routes/XBeautyManagement/TotalList')),
  },
  '/assetsManagementForUpoint/loanCreated': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanCreated')),
  },
  '/assetsManagementForUpoint/loanTransferring': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanTransferring')),
  },
  '/assetsManagementForUpoint/loanTransferFail': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanTransferFail')),
  },
  '/assetsManagementForUpoint/loanWaitToRepay': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanWaitToRepay')),
  },
  '/assetsManagementForUpoint/loanHaveRepayed': {
    component: dynamicWrapper(app, ['XBeautyManagement/loanBill'], () => import ('../routes/XBeautyManagement/LoanHaveRepayed')),
  },

  '/operatingCenterForUpoint/bannerConfig': {
    component: dynamicWrapper(app, ['OperatingCenter/bannerConfig'], () => import ('../routes/OperatingCenter/BannerConfig')),
  },
  '/operatingCenterForUpoint/flickerScreen': {
    component: dynamicWrapper(app, ['OperatingCenter/flickerScreen'], () => import ('../routes/OperatingCenter/FlickerScreen')),
  },
  '/operatingCenterForUpoint/homepageIcon': {
    component: dynamicWrapper(app, ['OperatingCenter/homepageIcon'], () => import ('../routes/OperatingCenter/HomepageIcon')),
  },
  '/operatingCenterForUpoint/loanSupermarket': {
    component: dynamicWrapper(app, ['OperatingCenter/loanSupermarket'], () => import ('../routes/OperatingCenter/LoanSupermarket')),
  },
  '/operatingCenterForUpoint/stageConfig': {
    component: dynamicWrapper(app, ['OperatingCenter/stageConfig'], () => import('../routes/OperatingCenter/StageConfig')),
  },
  '/operatingCenterForUpoint/functionSlot': {
    component: dynamicWrapper(app, ['OperatingCenter/functionSlot'], () => import('../routes/OperatingCenter/FunctionSlot')),
  },

  '/statisticsCenterForUpoint/conversionData': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/conversionData'], () => import ('../routes/StatisticsCenterForXBeauty/ConversionData')),
  },
  '/statisticsCenterForUpoint/backStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/backStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/BackStatistics')),
  },
  '/statisticsCenterForUpoint/grossProfit': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/grossProfit'], () => import ('../routes/StatisticsCenterForXBeauty/GrossProfit')),
  },
  '/statisticsCenterForUpoint/riskManagement': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/riskManagement'], () => import ('../routes/StatisticsCenterForXBeauty/RiskManagement')),
  },
  '/statisticsCenterForUpoint/loanStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/loanStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/LoanStatistics')),
  },
  '/statisticsCenterForUpoint/overdueStatistics': {
    component: dynamicWrapper(app, ['StatisticsCenterForXBeauty/overdueStatistics'], () => import ('../routes/StatisticsCenterForXBeauty/OverdueStatistics')),
  },

  '/channelCenterForUpoint/channelStatistics': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import ('../routes/ChannelCenterForXBeauty/ChannelStatistics')),
  },
  '/channelCenterForUpoint/channelDetail': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelStatistics'], () => import ('../routes/ChannelCenterForXBeauty/ChannelDetails')),
  },
  '/channelCenterForUpoint/channelConversion': {
    component: dynamicWrapper(app, ['ChannelCenterForXBeauty/channelConversion'], () => import ('../routes/ChannelCenterForXBeauty/ChannelConversion')),
  },

    '/user': {
      component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
    },
    '/user/login': {
      component: dynamicWrapper(app, ['login'], () => import('../routes/User/Login')),
    },

    '/result/success': {
      component: dynamicWrapper(app, [], () => import('../routes/Result/Success')),
    },
    '/result/fail': {
      component: dynamicWrapper(app, [], () => import('../routes/Result/Error')),
    },
    '/exception/403': {
      component: dynamicWrapper(app, [], () => import('../routes/Exception/403')),
    },
    '/exception/404': {
      component: dynamicWrapper(app, [], () => import('../routes/Exception/404')),
    },
    '/exception/500': {
      component: dynamicWrapper(app, [], () => import('../routes/Exception/500')),
    },
    '/exception/trigger': {
      component: dynamicWrapper(app, ['error'], () => import('../routes/Exception/triggerException')),
    },

    '/baseData/globalAutoCodeRule': {
      component: dynamicWrapper(app, ['BaseData/globalAutoCodeRule'], () => import('../routes/BaseData/GlobalAutoCodeRule')),
    },

  };
  // Get name from ./menu.js or just set it in the router data.
  const menuData = getFlatMenuData(getMenuData());
  const routerData = {};
  Object.keys(routerConfig).forEach((item) => {
    const menuItem = menuData[item.replace(/^\//, '')] || {};
    routerData[item] = {
      ...routerConfig[item],
      name: routerConfig[item].name || menuItem.name,
      authority: routerConfig[item].authority || menuItem.authority,
    };
  });
  return routerData;
};
